home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1U572S1 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.0 KB  |  55 lines

  1. package sun.net.www.protocol.systemresource;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7. import sun.net.www.URLConnection;
  8.  
  9. public class SystemResourceConnection extends URLConnection {
  10.    private static boolean debug;
  11.    private Object resource;
  12.    private SystemResourceManager manager;
  13.  
  14.    SystemResourceConnection(URL url) throws MalformedURLException, IOException {
  15.       super(url);
  16.       this.debug("SystemResourceConnection(" + url + ")");
  17.       this.manager = new SystemResourceManager(url);
  18.    }
  19.  
  20.    public void connect() throws IOException {
  21.       this.debug("Looking for " + super.url + " in SystemResourceManager");
  22.       Object o = this.manager.getLocalResource();
  23.       if (o == null) {
  24.          this.debug("Invalid resource name");
  25.          this.resource = null;
  26.       } else {
  27.          this.debug("Found resource");
  28.          this.resource = o;
  29.       }
  30.    }
  31.  
  32.    private void debug(String msg) {
  33.       if (debug) {
  34.          System.err.println(msg);
  35.       }
  36.  
  37.    }
  38.  
  39.    public Object getContent() throws IOException {
  40.       if (!super.connected) {
  41.          this.connect();
  42.       }
  43.  
  44.       return this.resource;
  45.    }
  46.  
  47.    public InputStream getInputStream() throws IOException {
  48.       if (!super.connected) {
  49.          this.connect();
  50.       }
  51.  
  52.       return this.resource instanceof InputStream ? (InputStream)this.resource : this.manager.getLocalResourceStream();
  53.    }
  54. }
  55.